package practice01;

public class Demo2 {
    public static void main(String[] args) {
        //1-100累加和 不使用循环
        int result = f(100);
        System.out.println(result);
        num();
        System.out.println(num);
    }
    static int a = 0,num = 0;
    public static void num(){
        a++;
        num += a;
        if (a==100){
            return;
        }
        num();
    }
    public static int f(int n){
        if (n==1) return 1;
        return n+f(n-1);
        //递归：逐层向下递进，然后在逐层向上归还
        //字符串的符合格式正确与否的规则
    }
}
